/**
 * 描述: 服务-首页管理
 * 版权: Copyright (c) 2019
 * 公司: 深圳市网商天下科技开发有限公司
 * 作者: 许堉颖
 * 版本: 1.0.0
 * 创建时间: 2019/04/29 16:52
 */
import {Service, RequestParams} from 'vue-element-simple';

// ====================订单管理
/**
 * 分页获取订单列表
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationGetOrderList = async function (params = {}) {
  const request = new RequestParams();
  // 页数
  request.put('page', params['page'], 1);
  // 每页条数
  request.put('pageSize', params['pageSize'], 20);
  // 模糊搜索
  request.put('search', params['search']);
  // 开始时间
  request.put('timeFrom', params['timeFrom']);
  // 结束时间
  request.put('timeTo', params['timeTo']);
  // 类型
  request.put('type', params['type']);
  // 状态
  request.put('status', params['status']);
  return await this.getService(`/admin/order/getPageList`, request);
};

/**
 * 修改订单状态
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationSetOrderStatus = async function (params = {}) {
  const request = new RequestParams();
  // 订单ID
  request.put('id', params['id']).checkEmpty('订单ID');
  // 订单状态  1启用；2禁用
  request.put('status', params['status']).checkEmpty('订单状态');
  return await this.getService(`/admin/order/changeStatus`, request);
};

/**
 * 根据id获取订单信息
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationGetOrderDetails = async function (params = {}) {
  const request = new RequestParams();
  // 页数
  request.put('id', params['id'], 1);
  return await this.getService(`/admin/order/getDetailsById`, request);
};

/**
 * 添加订单
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationAddOrder = async function (params = {}) {
  const request = new RequestParams();
  // 订单标题
  request.put('title', params['title']).checkEmpty('订单标题');
  // 订单
  request.put('icon', params['icon']).checkEmpty('订单');
  // 跳转路径
  request.put('url', params['url']);
  return await this.getService(`/admin/order/create`, request);
};

/**
 * 编辑订单
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationModifyOrder = async function (params = {}) {
  const request = new RequestParams();
  // 订单id
  request.put('id', params['id']).checkEmpty('订单ID');
  // 订单标题
  request.put('title', params['title']).checkEmpty('订单标题');
  // 订单
  request.put('icon', params['icon']).checkEmpty('订单');
  // 跳转路径
  request.put('url', params['url']);
  return await this.getService(`/admin/order/update`, request);
};

/**
 * 删除订单
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationDeleteOrder = async function (params = {}) {
  const request = new RequestParams();
  // 订单id
  request.put('id', params['id']).checkEmpty('订单ID');
  return await this.getService(`/admin/order/delete`, request);
};

/**
 * 重新派单
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationReassignAOrder = async function (params = {}) {
  const request = new RequestParams();
  // 订单id
  request.put('id', params['id']).checkEmpty('订单ID');
  return await this.getService(`/admin/order/updateAllotStatus`, request);
};

/**
 * 派单
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationAllocateOrders = async function (params = {}) {
  const request = new RequestParams();
  // 订单id
  request.put('id', params['id']).checkEmpty('订单ID');
  // 车辆ID
  request.put('carId', params['carId']).checkEmpty('车辆ID');
  // 司机ID
  request.put('driverId', params['driverId']).checkEmpty('司机ID');
  // 通知方式
  request.put('notify', params['notify']);
  return await this.getService(`/admin/order/updateAllot`, request);
};

/**
 * 退款
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationRefundOrders = async function (params = {}) {
  const request = new RequestParams();
  // 车辆ID
  request.put('orderSn', params['orderSn']).checkEmpty('订单号');
  // 司机ID
  request.put('status', params['status']).checkEmpty('状态');
  // 通知方式
  request.put('reason', params['reason']);
  // 退款金额
  request.put('money', params['money']);
  return await this.getService(`/admin/order/toHandleRefund`, request);
};
// ====================订单管理

// ====================订单设置
/**
 * 获取订单设置信息
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationGetOrderSetting = async function (params = {}) {
  const request = new RequestParams();
  return await this.getService(`/admin/order/setting/obtain`, request);
};
/**
 * 更新订单设置
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationUpdateOrderSetting = async function (params = {}) {
  const request = new RequestParams();
  // 支付超时时间
  request.put('cancelTime', params['cancelTime']).checkEmpty('支付超时时间');
  return await this.getService(`/admin/order/setting/save`, request);
};

/**
 * 获取订单设置信息
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationGetOrderRemindSetting = async function (params = {}) {
  const request = new RequestParams();
  return await this.getService(`/admin/order/remindSetting/obtain`, request);
};

/**
 * 更新订单设置
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationUpdateOrderRemindSetting = async function (params = {}) {
  const request = new RequestParams();
  // 支付超时时间
  request.put('status1', params.remind1['status'] ? 1 : 0);
  request.put('status2', params.remind2['status'] ? 1 : 0);
  request.put('status3', params.remind3['status'] ? 1 : 0);
  request.put('status4', params.remind4['status'] ? 1 : 0);
  request.put('status5', params.remind5['status'] ? 1 : 0);
  request.put('value1', params.remind1['value']);
  request.put('value2', params.remind2['value']);
  request.put('value3', params.remind3['value']);
  request.put('value4', params.remind4['value']);
  request.put('value5', params.remind5['value']);
  return await this.getService(`/admin/order/remindSetting/save`, request);
};
// ====================订单设置

// ====================退改规则管理
/**
 * 获取退改规则
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationGetCancelRule = async function () {
  const request = new RequestParams();
  return await this.getService(`/admin/system/getConfig/ruleContent`, request);
};

/**
 * 修改退改规则
 * @param params
 * @returns {Promise.<*>}
 */
Service.applicationModifyCancelRule = async function (params = {}) {
  const request = new RequestParams();
  // 审核方式
  request.put('refundVerifyStatus', params['refundVerifyStatus']);
  // 内容
  request.put('ruleContent', params['ruleContent']).checkEmpty('内容');
  // 规则列表
  request.put('orderCancelRule', params['orderCancelRule']);
  return await this.getService(`/admin/system/saveConfig/ruleContent`, request);
};
